<template>
	<!-- 站内消息 -->
	<view class="container">
		<view class="contain_top">
			<text>{{ unReadArr.length }}条未读消息</text>
			<image class="top_img" src="https://tcjyh2022.oss-cn-hangzhou.aliyuncs.com/nywx/clear_notice.svg" mode=""
				@tap="clearNotice"></image>
		</view>
		<view class="contain_body">
			<view class="contain_item1" v-for="(item, index) in noticeList" :key="index">
				<view class="contain_item1_top">
					<view class="item1_top_l">
						<text v-if="item.status == 1" class="top_l_dian"></text>
						<text>{{ returnType(item.type) }}</text>
					</view>
					<view class="item1_top_r">
						{{ item._add_time_str }}
					</view>
				</view>
				<view class="item1_bottom">
					{{ item.msg }}{{ item.amount }}
				</view>
			</view>
      <view class="no-data" v-if="noticeList.length == 0">暂无消息</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			noticeList: [], //0已读 1未读
			page: 1, // 未读
			limit: 100,
			total: 0, // 未读
			isNoMore: 'nomore',
      unReadArr: [],
      userInfo: {}
		}
	},
	// 上拉加载
	onReachBottom() {
	},
	onLoad() {
    this.userInfo = vk.getVuex('$user.userInfo')
	},
  onShow() {
    this.getNoticeList(); //获取消息列表
  },
	methods: {
		returnType(type) {
			if (type == 1) {
				return '返利消息'
			}
			if (type == 2) {
				return '系统消息'
			}
			if (type == 3) {
				return '提现消息'
			}
			if (type == 4) {
				return '审核消息'
			}
		},
		//获取消息列表
		getNoticeList() {
      vk.callFunction({
        url: 'user/kh/messageList',
        title: '加载中...',
        data: {
          user_id: this.userInfo._id,
        },
        success: (res) => {
          if(res.rows.length> 0) {
            res.rows.map(item => {
              if (item.status == 1) {
                this.unReadArr.push(item)
              }
            })
          }
          this.noticeList = res.rows
        }
      })
		},
		// 清除已读
		clearNotice() {
			let ids = this.unReadArr.map(item => {
				return item._id
			})
      if (ids.length >0) {
        vk.callFunction({
          url: 'user/kh/messageReadAll',
          title: '加载中...',
          data: {
            ids
          },
          success: (res) => {
            this.unReadArr = []
            this.getNoticeList()
          }
        })
      }
		}
	}
}
</script>

<style scoped lang="scss">
.container {
	padding: 0 30rpx;

	.contain_top {
		display: flex;
		align-items: center;
		padding: 22rpx 0 20rpx;
		font-size: 26rpx;

		.top_img {
			width: 30rpx;
			height: 30rpx;
			margin-left: 20rpx;
		}
	}

	.contain_body {
		.contain_item1 {
			margin-bottom: 24rpx;
			padding: 30rpx 24rpx;
			background-color: #fff;
			border-radius: 18rpx;

			.contain_item1_top {
				display: flex;
				justify-content: space-between;
				align-items: center;

				.item1_top_l {
					display: flex;
					align-items: center;
					font-size: 28rpx;

					.top_l_dian {
						display: inline-block;
						width: 14rpx;
						height: 14rpx;
						margin-right: 20rpx;
						border-radius: 50%;
						background: #FF774D;
					}
				}

				.item1_top_r {
					font-size: 22rpx;
				}
			}

			.item1_bottom {
				margin-top: 22rpx;
				font-size: 26rpx;
				line-height: 38rpx;
			}
		}

		.contain_item2 {
			color: rgba(0, 0, 0, 0.3);
		}
	}
  .no-data {
    width: 100%;
    text-align: center;
    font-family: PingFang SC;
    font-size: 24rpx;
    font-style: normal;
    font-weight: 400;
    margin-top: 100rpx;
  }
}</style>
